package com.zone.vehicle.superApps.model;

import androidx.annotation.NonNull;
import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider;

import com.zone.vehicle.superApps.datasource.AppManagerDataSource;
import com.zone.vehicle.superApps.datasource.HomeDataSource;
import com.zone.vehicle.superApps.datasource.LoginDataSource;
import com.zone.vehicle.superApps.repository.AppManagerRepository;
import com.zone.vehicle.superApps.repository.HomeRepository;
import com.zone.vehicle.superApps.repository.LoginRepository;

/**
 * ViewModel provider factory to instantiate LoginViewModel.
 * Required given LoginViewModel has a non-empty constructor
 */
public class ViewModelFactory implements ViewModelProvider.Factory {

    @NonNull
    @Override
    @SuppressWarnings("unchecked")
    public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
        if (modelClass.isAssignableFrom(LoginViewModel.class)) {
            return (T) new LoginViewModel(LoginRepository.getInstance(new LoginDataSource()));
        } else if (modelClass.isAssignableFrom(HomeViewModel.class)) {
            return (T) new HomeViewModel(HomeRepository.getInstance(new HomeDataSource()));
        }  else if (modelClass.isAssignableFrom(AppManagerViewModel.class)) {
            return (T) new AppManagerViewModel(AppManagerRepository.getInstance(new AppManagerDataSource()));
        } else {
            throw new IllegalArgumentException("Unknown ViewModel class");
        }
    }
}